package org.zsl.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.zsl.dao.ProductMapper;
import org.zsl.model.Product;
import org.zsl.model.ResponseMessage;
import org.zsl.service.ProductService;

import java.util.List;

@RestController
@RequestMapping("/pro")
public class ProductController {


    @Autowired
    private ProductService productService;

    @RequestMapping("/test")
    public ResponseMessage test(){

        ResponseMessage responseMessage = new ResponseMessage();

        responseMessage.setMessage("hello Spring MVC");

        return  responseMessage;
    }


    @RequestMapping("/list")
    public List<Product> getList(){

        return  productService.getList();
    }

    @RequestMapping(value = "/edit",method = RequestMethod.POST)
    public ResponseMessage edit(Product product){
        return  productService.edit(product);
    }

    @RequestMapping(value = "/remove/{id}",method = RequestMethod.POST)
    public ResponseMessage remove(@PathVariable("id") Integer id){
        return  productService.remove(id);
    }


}
